<template>
  <div class="test">
    <div class="container">
      <h1>添加音乐到播放器</h1>
      <text>还未选择任何文件</text>
      <el-button class="container_btn" @click="changeMusic">选择音乐</el-button>
      <!-- <div id="message" class="mb-2">您还未选择任何音乐文件</div> -->
      <ul>
        <li v-if="musicList.length == 0">您还未选择任何音乐文件</li>
        <li v-for="item in musicList" :key="item">{{ item }}</li>
      </ul>
      <el-button type="primary" class="container_btn" @click="improtMusic"
        >导入音乐</el-button
      >
    </div>
  </div>
</template>

<script>
const { ipcRenderer } = require("electron");
const path = require("path");
export default {
  name: "add",
  data() {
    return {
      musicList: [],
    };
  },
  methods: {
    changeMusic() {
      //选择音乐打开 
      ipcRenderer.send("openMusicFile");
      ipcRenderer.on("dialogReply", (event, arg) => {
        if (arg) {
          // this.musicList = arg.map((item) => {
          //   return path.basename(item);
          // });
          this.musicList =arg
        }
        console.log('this.musicList',this.musicList);
        // document.getElementById("message").innerHTML = arg;
      });
    },
    improtMusic() {
      ipcRenderer.send("improtMusic", this.musicList);
    },
  },
};
</script>

<style scoped lang="scss">
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.test {
  height: 100%;
  width: 100%;
}
.container {
  padding-top: 50px;
  text-align: center;
  &_btn {
    margin-top: 50px;
    width: 80%;
  }
}
</style>
